<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <h2>异步案例分析</h2>
</body>
<script>
    //事件循环 event loop 宏任务/微任务
    (function() {
        setTimeout(() => {
            console.log(0) //1
        })

        new Promise(resolve => {

            setTimeout(() => {
                resolve()
                Promise.resolve().then(() => console.log(2)) //4
                console.log(3) //2
            })
        }).then(() => {
            console.log(5) //3
            Promise.resolve().then(() => console.log(8)) //5
            setTimeout(() => console.log(6)) //6
        })
    })()
</script>

</html>